Page({
  data: {
    contacts: []
  },
  
  onLoad() {
    this.loadContacts()
  },
  
  onShow() {
    this.loadContacts()
  },
  
  loadContacts() {
    const contacts = wx.getStorageSync('contacts') || []
    this.setData({
      contacts
    })
  },
  
  addContact() {
    wx.navigateTo({
      url: '/pages/add-contact/add-contact'
    })
  },
  
  editContact(e) {
    const index = e.currentTarget.dataset.index
    wx.navigateTo({
      url: `/pages/add-contact/add-contact?index=${index}`
    })
  }
})


